
const app = getApp();
const req = require("../../utils/http.js");
Page({

  data: {
    userInfo:'',
    newList:[],
    page:1,
    size:10
  },

  // 查询当前用户
  isUserinfo() {
    let t = this
    let params = {}
    req.wxReq('/coupon/wxUser/isUserinfo', "GET", params).then(res => {
      t.setData({
        userInfo: res.data.result
      })
    })
  },
  //积分明细
  getPointsDetailList(page,size){
    let t = this
    let params = {}
    req.wxReq(`/coupon/wxUser/getPointsDetailList/${page}/${size}`,"GET",params).then(res=>{
      if(res.data.code==200){
        let list = res.data.result.records
        let newList = t.data.newList.concat(list)
        t.setData({
          newList,
          total: res.data.result.total
        })
  
      }else{
        wx.showToast({
          title: res.data.message,
          icon:'none',
          duration:1500
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let t = this
    let page = t.data.page;
    let size = t.data.size;
    t.isUserinfo()
    t.getPointsDetailList(page,size)
    //加载页面
    wx.getSystemInfo({
      success: (res) => {
        this.setData({
          height: res.windowHeight
        })

      }
    })
  },



  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    let t = this
    wx.showLoading({
      title: '玩命加载...',
    })
    var page = t.data.page + 1;
    t.setData({
      page: page
    })
    if (page > Math.ceil(t.data.total / t.data.size)) {
      wx.showToast({
        title: '到底了！！！',
        icon: 'none'
      })
      return;
    };
    t.getPointsDetailList(page, t.data.size);
    wx.hideLoading()
  },


})
